Skip to content

Conversation

@whlpatricia
Copy link

Added user authentication with email and password. For now the tmp page displays the user token when signed in successfully.
{9D6269CA-8093-4745-A70E-E7832EF0B0A0}

@vercel
Copy link

vercel bot commented Nov 22, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
trcc Error Error Nov 22, 2025 4:16am

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR implements user authentication with email and password using Supabase, adding sign-in, sign-up, and email confirmation flows. However, there are several critical issues that need to be addressed, including incorrect file naming for Next.js middleware, incorrect import paths, missing error pages, and security vulnerabilities.

Key Changes

  • Added Supabase authentication functions for email/password sign-up and sign-in
  • Created a temporary login page with forms for testing authentication
  • Implemented email confirmation route handler for Supabase OTP verification
  • Added middleware (incorrectly named as proxy.ts) for session management and route protection

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 9 comments.

Show a summary per file
File Description
src/proxy.ts Middleware entry point with incorrect naming and import path - should be middleware.ts
src/lib/client/supabase/proxy.ts Session management middleware logic for protecting routes
src/lib/client/supabase/client.ts Browser client initialization for Supabase
src/lib/client/supabase/auth.ts Authentication functions for email/password sign-up and sign-in
src/app/login/page.tsx Temporary UI for testing authentication flows
src/app/auth/confirm/route.ts Email confirmation handler with open redirect vulnerability

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@@ -0,0 +1,20 @@
import { updateSession } from "@/lib/supabase/proxy";
Copy link

Copilot AI Nov 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The import path is incorrect. The file proxy.ts is located at src/lib/client/supabase/proxy.ts, not @/lib/supabase/proxy. This should be @/lib/client/supabase/proxy to match the actual file location.

Suggested change
import { updateSession } from "@/lib/supabase/proxy";
import { updateSession } from "@/lib/client/supabase/proxy";

Copilot uses AI. Check for mistakes.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Double check this

import { updateSession } from "@/lib/supabase/proxy";
import { type NextRequest } from "next/server";

export async function proxy(request: NextRequest) {
Copy link

Copilot AI Nov 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file should be named middleware.ts rather than proxy.ts and placed at the root of src/ directory. Next.js expects middleware to be exported from a file named middleware.ts at the root of the src directory (or project root). The exported function should also be named middleware instead of proxy.

Suggested change
export async function proxy(request: NextRequest) {
export async function middleware(request: NextRequest) {

Copilot uses AI. Check for mistakes.
Copy link
Member

@LeandroHamaguchi LeandroHamaguchi Nov 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the name proxy.ts for this file work? Because for the Next.js version (15.5.6) we're using it asks for the function to be called middleware. The newest version (16) of Next.js requires proxy.ts instead of middleware.ts, but in the version we're using this isn't used yet.

Comment on lines +9 to +16
export async function signInWithEmail(email: string, password: string) {
const supabase = createClient();
const { data, error } = await supabase.auth.signInWithPassword({
email,
password,
});
return { data, error };
}
Copy link

Copilot AI Nov 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding email format validation before calling the Supabase API. While the HTML input type="email" provides basic validation, additional checks in the auth functions would provide defense-in-depth and ensure consistent validation if these functions are called from other contexts.

Copilot uses AI. Check for mistakes.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can ignore this for now for the same reason that we ignore the password checks. Performing these strength requirements checks on the frontend would provide faster feedback to the user.

Comment on lines +11 to +22
const next = searchParams.get('next') ?? '/'

if (token_hash && type) {
const supabase = await createClient()

const { error } = await supabase.auth.verifyOtp({
type,
token_hash,
})
if (!error) {
// redirect user to specified redirect URL or root of app
redirect(next)
Copy link

Copilot AI Nov 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The next parameter from search params is used directly for redirection without validation. This creates an open redirect vulnerability where attackers could craft malicious links to redirect users to external sites after authentication. Validate that the redirect URL is relative or on the same domain before using it.

Copilot uses AI. Check for mistakes.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is good practice


export async function signUpWithEmail(email: string, password: string) {
const supabase = createClient();
const { data, error } = await supabase.auth.signUp({ email, password });
Copy link

Copilot AI Nov 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The signUpWithEmail function should include an emailRedirectTo option to specify where users should be redirected after confirming their email. Without this, the confirmation link may not work correctly with the /auth/confirm route. Consider adding: options: { emailRedirectTo: ${window.location.origin}/auth/confirm }

Suggested change
const { data, error } = await supabase.auth.signUp({ email, password });
const { data, error } = await supabase.auth.signUp(
{ email, password },
{ emailRedirectTo: `${window.location.origin}/auth/confirm` }
);

Copilot uses AI. Check for mistakes.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the confirmation link work properly?

Comment on lines +1 to +5
import { type EmailOtpType } from '@supabase/supabase-js'
import { type NextRequest } from 'next/server'

import { createClient } from '@/lib/client/supabase/server'
import { redirect } from 'next/navigation'
Copy link

Copilot AI Nov 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inconsistent quote style. This file uses single quotes while other files in the codebase use double quotes (e.g., src/lib/client/supabase/client.ts, src/lib/client/supabase/auth.ts). Consider using double quotes for consistency with the rest of the codebase.

Copilot uses AI. Check for mistakes.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is also the errors Vercel points out. Make sure you're up-to-date with the latest main branch! There's code in the main branch that runs formatting/linting automatically for you before every commit.

}

// redirect the user to an error page with some instructions
redirect('/auth/auth-code-error')
Copy link

Copilot AI Nov 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The route redirects to /auth/auth-code-error but this page doesn't exist in the codebase. This will result in a 404 error when email confirmation fails. You need to create the error page at src/app/auth/auth-code-error/page.tsx.

Copilot uses AI. Check for mistakes.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can just create a very basic page

Copy link
Member

@LeandroHamaguchi LeandroHamaguchi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was one of the hardest tickets, and overall, great work Patricia!

}

// redirect the user to an error page with some instructions
redirect('/auth/auth-code-error')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can just create a very basic page

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should use a different name for this file since it's the same as src/proxy.ts

Comment on lines +1 to +5
import { type EmailOtpType } from '@supabase/supabase-js'
import { type NextRequest } from 'next/server'

import { createClient } from '@/lib/client/supabase/server'
import { redirect } from 'next/navigation'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is also the errors Vercel points out. Make sure you're up-to-date with the latest main branch! There's code in the main branch that runs formatting/linting automatically for you before every commit.

Comment on lines +11 to +22
const next = searchParams.get('next') ?? '/'

if (token_hash && type) {
const supabase = await createClient()

const { error } = await supabase.auth.verifyOtp({
type,
token_hash,
})
if (!error) {
// redirect user to specified redirect URL or root of app
redirect(next)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is good practice


export async function signUpWithEmail(email: string, password: string) {
const supabase = createClient();
const { data, error } = await supabase.auth.signUp({ email, password });
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the confirmation link work properly?

@@ -0,0 +1,20 @@
import { updateSession } from "@/lib/supabase/proxy";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Double check this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BE 2 - Implement User Authentication with Email + Password

3 participants